package com.qianfeng.xinyihezi.xinyihezi.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.qianfeng.xinyihezi.xinyihezi.R;
import com.qianfeng.xinyihezi.xinyihezi.activity.XinYiActivity;
import com.qianfeng.xinyihezi.xinyihezi.model.AllBean;

import java.util.List;

/**
 * 作者：王加威 on 2016/11/14 08:55
 */

public class MyItemsRecyclerViewAdapter extends RecyclerView.Adapter {
    private Context mContext;
    private List<AllBean.DataBean.ActivityBean>mActivityBeen;
    private MyRecyclerViewAdapter mAdapter;

    public MyItemsRecyclerViewAdapter(Context context, List<AllBean.DataBean.ActivityBean> activityBeen) {
        mContext = context;
        mActivityBeen = activityBeen;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_adapter,null);
        RecyclerView.ViewHolder holder=new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder,  int position) {
        ViewHolder viewHolder= (ViewHolder) holder;
        Glide.with(mContext).load(mActivityBeen.get(position).url).into(viewHolder.iv);
        final int count=position;
        viewHolder.iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext, XinYiActivity.class);
                intent.putExtra("url",mActivityBeen.get(count).theme_id+"");
                mContext.startActivity(intent);
            }
        });
       mAdapter=new MyRecyclerViewAdapter(mContext,mActivityBeen.get(position).goods);
        viewHolder.mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL,false));
        viewHolder.mRecyclerView.setAdapter(mAdapter);
    }

    @Override
    public int getItemCount() {
        return mActivityBeen.size();
    }

    private static class ViewHolder extends RecyclerView.ViewHolder{
        private ImageView iv;
        private RecyclerView mRecyclerView;

        public ViewHolder(View itemView) {
            super(itemView);
            iv= (ImageView) itemView.findViewById(R.id.item_adapter_iv);
            mRecyclerView= (RecyclerView) itemView.findViewById(R.id.item_adapter_RecyclerView);
        }
    }
}
